﻿using Dou.UI;
using UnityEngine;

namespace Simple
{
    public class Test_TabBtn : MonoBehaviour
    {
        // 数据，这里就直接写死，实际使用时由外部设置
        public string label;
        public bool hasRed;
        
        public DToggle toggle;
        
        public RectTransform unselectedGO;
        public RectTransform selectedGO;
        
        public DTextMeshProUGUI text;
        public RectTransform redPoint;
        
        void Awake()
        {
            text.text = label;
            redPoint.gameObject.SetActive(hasRed);
            
            toggle.onValueChanged.AddListener(OnTabChanged);
        }

        private void OnTabChanged(bool selected)
        {
            if (selected)
            {
                unselectedGO.gameObject.SetActive(false);
                selectedGO.gameObject.SetActive(true);
            }
            else
            {
                unselectedGO.gameObject.SetActive(true);
                selectedGO.gameObject.SetActive(false);
            }
        }
    }
}
